package com.example.demo.controller;

import com.example.demo.utils.QRCodeUtils;
import com.google.zxing.WriterException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.IOException;

@RequestMapping("app")
@RestController
public class QRController {

    // 二维码生成测试
    @GetMapping("/get/test1")
    public void test1() throws IOException, WriterException {
        String url = "http://localhost:5173/#/pages/home/Detail?artifact=%257B%2522id%2522%253A4%252C%2522name%2522%253A%2522%25E5%2594%2590%25E4%25B8%2589%25E5%25BD%25A9%25E9%25A9%25AC%2522%252C%2522image%2522%253A%2522https%253A%252F%252Ftse3-mm.cn.bing.net%252Fth%252Fid%252FOIP-C.MmLo-q77PQpEZIOydnIjfQAAAA%253Frs%253D1%2526pid%253DImgDetMain%2526cb%253Didpwebpc2%2522%252C%2522dynasty%2522%253A%2522%25E5%2594%2590%25E4%25BB%25A3%2522%252C%2522location%2522%253A%2522%25E6%25B9%2596%25E5%258D%2597%25E6%25A0%25AA%25E6%25B4%25B2%2522%252C%2522description%2522%253A%2522%25E5%2594%2590%25E4%25BB%25A3%25E4%25B8%2589%25E5%25BD%25A9%25E9%2599%25B6%25E9%25A9%25AC%25EF%25BC%258C%25E9%25AB%259860%25E5%258E%2598%25E7%25B1%25B3%25EF%25BC%258C%25E9%2595%25BF70%25E5%258E%2598%25E7%25B1%25B3%25EF%25BC%258C%25E9%2580%25A0%25E5%259E%258B%25E7%2594%259F%25E5%258A%25A8%25EF%25BC%258C%25E8%2589%25B2%25E5%25BD%25A9%25E8%2589%25B3%25E4%25B8%25BD%25EF%25BC%258C%25E4%25BD%2593%25E7%258E%25B0%25E4%25BA%2586%25E5%2594%2590%25E4%25BB%25A3%25E9%2599%25B6%25E8%2589%25BA%25E7%259A%2584%25E9%25AB%2598%25E8%25B6%2585%25E6%25B0%25B4%25E5%25B9%25B3%25E3%2580%2582%2522%257D";
        int size = 300;
        String fileType = "png";
        File qrFile = new File("src/main/resources/template/test4.png");
        try {
            QRCodeUtils.createQRCode(url,size,fileType,qrFile);
            System.out.println("success");
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }

    // 二维码扫描跳转测试
    @GetMapping("/get/test2")
    public void test2(){
        String filepath = "src/main/resources/template/test4.png";
        String url = QRCodeUtils.scanQRCode(filepath);
    }
}
